package com.example.walletmodule.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
public class CommonResult<T> {
    private static final long serialVersionUID = 5778573516446596671L;
    public static int SUCCESS = 0;
    public static int FAIL = -1;
    public static String MSG_SUCCESS = "成功";
    public static String MSG_FAIL = "失败";
    private int code = 0;
    private String msg;
    private T data;

    public CommonResult(){}

    public CommonResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> CommonResult<T> success(T data, String msg) {
        msg = msg != null && msg.length() > 0 ? msg : MSG_SUCCESS;
        return new CommonResult(SUCCESS, msg, data);
    }

    public static <T> CommonResult<T> fail(T data, String msg) {
        msg = msg != null && msg.length() > 0 ? msg : MSG_FAIL;
        return new CommonResult(FAIL, msg, data);
    }


}
